<template>
    <div :id="id" ref="canvas" class="canvas" :style="{width: '100%', height: canHeight + 'px'}"></div>
</template>
<script setup lang="ts">
import { defineProps, computed, onMounted } from 'vue'
import * as echarts from 'echarts/core';
import {
  TitleComponent,
  ToolboxComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent
} from 'echarts/components';
import { LineChart } from 'echarts/charts';
import { UniversalTransition } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';

echarts.use([
  TitleComponent,
  ToolboxComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
  LineChart,
  CanvasRenderer,
  UniversalTransition
]);
type EChartsOption = echarts.ComposeOption<
  GridComponentOption | PieSeriesOption | LegendComponentOption | TitleComponentOption
  |ToolboxComponentOption |TooltipComponentOption
>;
const props = defineProps({
    id: {
        type: String,
        default: "pie" 
    },
    canvasHeight: {
        type:Number,
        default: 300
    },
    data: {
        type: Object,
        default: () => {} 
    }
})
let canHeight = computed(() => { return props.canvasHeight })
onMounted(() => {
    console.log('打印:', props)
    var chartDom = document.getElementById(props.id);
    var myChart = echarts.init(chartDom);
    var option: EChartsOption;

    option = {
        title: {
            text: '月度出入库量',
            textStyle: {
                fontSize: 16,
                color: '#ffffff'
            },
            left: 15
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            sgow: true,
            left: 'center',
            top: 20,
            bottom: 20,
            textStyle: {color: '#fff'},
            data: props.data.seriesDataList.map(m => m.name)
        },
        grid: {
            top: '20%',
            left: 20,
            right: 20,
            bottom: 20,
            containLabel: true
        },
        toolbox: {
            show: false,
            feature: {
            saveAsImage: {}
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: props.data.xAxisDataList
        },
        yAxis: {
            type: 'value',
            axisLine: {show: false},
            splitLine:{show: true, lineStyle:{color: '#01176d'}},
        },
        series: props.data.seriesDataList
    };

    option && myChart.setOption(option);
})
</script>

<style scope>
</style>